﻿using System;
using System.Collections.Generic;
using System.Windows.Forms;
using Autodesk.Revit.UI;

namespace YArchitech.Plumbing
{
	public class DataOperateHelper
	{
		public DataOperateHelper(UIDocument doc)
		{
			this.uiDoc = doc;
		}

		public void BindDataGridHeader(IList<string> listHeader, DataGridView dataGridView)
		{
			foreach (string text in listHeader)
			{
				if (text == "公称外径")
				{
					DataGridViewComboBoxColumn dataGridViewComboBoxColumn = new DataGridViewComboBoxColumn();
					dataGridViewComboBoxColumn.DisplayStyle = DataGridViewComboBoxDisplayStyle.Nothing;
					dataGridViewComboBoxColumn.HeaderText = text;
					dataGridViewComboBoxColumn.Name = text;
					dataGridViewComboBoxColumn.DefaultCellStyle.Format = "N" + 3;
					dataGridViewComboBoxColumn.SortMode = DataGridViewColumnSortMode.Automatic;
					dataGridView.Columns.Add(dataGridViewComboBoxColumn);
				}
				else
				{
					DataGridViewTextBoxColumn dataGridViewTextBoxColumn = new DataGridViewTextBoxColumn();
					if (text != "公称直径(mm)")
					{
						dataGridViewTextBoxColumn.ReadOnly = true;
					}
					if (text == "管道对象")
					{
						dataGridViewTextBoxColumn.Visible = false;
					}
					dataGridViewTextBoxColumn.HeaderText = text;
					dataGridViewTextBoxColumn.Name = text;
					dataGridViewTextBoxColumn.SortMode = DataGridViewColumnSortMode.NotSortable;
					if (text == "长度(m)" || text == "水力坡降(mH2O/m)" || text == "沿程阻力(m)")
					{
						dataGridViewTextBoxColumn.DefaultCellStyle.Format = "N" + 3;
					}
					else if (text == "管段编号" || text == "公称直径(mm)")
					{
						dataGridViewTextBoxColumn.DefaultCellStyle.Format = "N" + 0;
					}
					else
					{
						dataGridViewTextBoxColumn.DefaultCellStyle.Format = "N" + 2;
					}
					dataGridView.Columns.Add(dataGridViewTextBoxColumn);
				}
			}
		}

		public void BindDataGridData(DataGridView dataGridView, HYSystemCal hySystemCal, bool IsAllData)
		{
			List<HYPipeCal> list = new List<HYPipeCal>();
			if (IsAllData)
			{
				list = hySystemCal.PipeCals;
			}
			else
			{
				list = hySystemCal.MainPipeCals;
			}
			double num = 0.0;
			foreach (HYPipeCal hypipeCal in list)
			{
				if (hySystemCal.systemType == HYSystemCal.SystemType.Drainage)
				{
					dataGridView.Rows.Add(new object[]
					{
						hypipeCal,
						hypipeCal.Number,
						hypipeCal.dGrad,
						hypipeCal.Flow,
						hypipeCal.Velocity,
						hypipeCal.Length,
						hypipeCal.nDN,
						hypipeCal.dFullness,
						hypipeCal.Equivalent(HYSystemCal.SystemType.Drainage)
					});
				}
				else if (hySystemCal.systemType == HYSystemCal.SystemType.Feed)
				{
					dataGridView.Rows.Add(new object[]
					{
						hypipeCal,
						hypipeCal.Number,
						hypipeCal.Flow,
						hypipeCal.Velocity,
						hypipeCal.dLostWator,
						hypipeCal.Length,
						hypipeCal.nDN,
						hypipeCal.Equivalent(HYSystemCal.SystemType.Feed),
						hypipeCal.LossPipe
					});
				}
				else if (hySystemCal.systemType == HYSystemCal.SystemType.Fire)
				{
					num += hypipeCal.dLostWator;
					dataGridView.Rows.Add(new object[]
					{
						hypipeCal,
						hypipeCal.Number,
						hypipeCal.Flow,
						hypipeCal.Velocity,
						hypipeCal.Length,
						hypipeCal.nDN,
						hypipeCal.dLostWator / hypipeCal.Length,
						hypipeCal.dLostWator
					});
				}
			}
		}

		public void BindDataGridDataByList(DataGridView dataGridView, List<HYPipeCal> listPipe)
		{
			double num = 0.0;
			foreach (HYPipeCal hypipeCal in listPipe)
			{
				if (this.SysType == HYSystemCal.SystemType.Drainage)
				{
					dataGridView.Rows.Add(new object[]
					{
						hypipeCal,
						hypipeCal.Number,
						hypipeCal.dGrad,
						hypipeCal.Flow,
						hypipeCal.Velocity,
						hypipeCal.Length,
						hypipeCal.nDN,
						hypipeCal.dFullness,
						hypipeCal.Equivalent(HYSystemCal.SystemType.Drainage)
					});
				}
				else if (this.SysType == HYSystemCal.SystemType.Feed)
				{
					dataGridView.Rows.Add(new object[]
					{
						hypipeCal,
						hypipeCal.Number,
						hypipeCal.Flow,
						hypipeCal.Velocity,
						hypipeCal.dLostWator,
						hypipeCal.Length,
						hypipeCal.nDN,
						hypipeCal.Equivalent(HYSystemCal.SystemType.Feed),
						hypipeCal.LossPipe
					});
				}
				else if (this.SysType == HYSystemCal.SystemType.Fire)
				{
					num += hypipeCal.dLostWator;
					dataGridView.Rows.Add(new object[]
					{
						hypipeCal,
						hypipeCal.Number,
						hypipeCal.Flow,
						hypipeCal.Velocity,
						hypipeCal.Length,
						hypipeCal.nDN,
						hypipeCal.dLostWator / hypipeCal.Length,
						hypipeCal.dLostWator,
						num
					});
				}
			}
		}

		public UIDocument uiDoc;

		public HYSystemCal.SystemType SysType;
	}
}
